
import store from '../store/index.js'

export default function({ $axios, redirect }) {

	$axios.interceptors.request.use(function(config){
			if (config.params.showLoading) {			
				store().dispatch('showloader')
			}
			config.params.t = Date.parse(new Date())/1000
		    if (config.params.token) {	
			 if (process.client) {
			    const token = localStorage.getItem('accessToken')
			    if (token) {
			       config.headers.common['X-CSRFToken'] = token;
			    } 
			  }
			}
	            return config;
	        }, err => {
			store().dispatch('hideloader')
	        return Promise.reject(err)
	})


	// http响应拦截器
	$axios.interceptors.response.use(function(response){
		   if (response.config.params.showLoading) {
			  //store().dispatch('hideloader')
		   }
	          return response;
	       }, err => {
	          return Promise.reject(err);
	})

}